<?php

Yii::import('zii.widgets.CMenu');

class MyMenu extends CMenu
{
	/**
	 * Normalizes the {@link items} property so that the 'active' state is properly identified for every menu item.
	 * @param array the items to be normalized.
	 * @param string the route of the current request.
	 * @param boolean whether there is an active child menu item.
	 * @return array the normalized menu items
	 */
	protected function normalizeItems($items,$route,&$active)
	{
		foreach($items as $i=>$item)
		{
			if(isset($item['visible']) && !$item['visible'])
			{
				unset($items[$i]);
				continue;
			}
			if($this->encodeLabel)
				$items[$i]['label']=CHtml::encode($item['label']);
			$hasActiveChild=false;
			if(isset($item['items']))
			{
				$items[$i]['items']=$this->normalizeItems($item['items'],$route,$hasActiveChild);
				if(empty($items[$i]['items']) && $this->hideEmptyItems)
					unset($items[$i]['items']);
			}
			if(!isset($item['active']))
			{
				if($this->activateParents && $hasActiveChild || $this->isItemActive($item,$route))
					$active=$items[$i]['active']=true;
				else
					$items[$i]['active']=false;
			}
			else if($item['active'])
				$active=true;
			if($items[$i]['active'] && $this->activeCssClass!='')
			{
				if(isset($item['linkOptions']['class']))
				{
					$items[$i]['linkOptions']['class'].=' '.$this->activeCssClass;
					$items[$i]['itemOptions']['class'].=' '.$this->activeCssClass;
				} else {
					$items[$i]['linkOptions']['class']=$this->activeCssClass;
					$items[$i]['itemOptions']['class']=$this->activeCssClass;
				}
			}
		}
		return array_values($items);
	}

}